package com.iscas.green.logchaostest.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api")
public class LogTestController {

    // 定时任务，每5秒记录一条日志
//    @Scheduled(fixedRate = 5000)
//    public void scheduledLogging() {
//        log.info("Scheduled task - Regular logging at: {}", System.currentTimeMillis());
//    }

    // 测试大量日志输出
    @GetMapping("/bulk-logs")
    public String testBulkLogs() {
        log.info("Bulk log test - Message #{}", 6662025);
        return "Bulk logs generated";
    }

    // 测试异常日志
    @GetMapping("/test/error-log")
    public String testErrorLog() {
        try {
            throw new RuntimeException("Test exception for logging");
        } catch (Exception e) {
            log.error("Error occurred during test", e);
        }
        return "Error log generated";
    }
}